package com.ccit.dao;

import com.ccit.domain.AttendanceType;
import com.ccit.domain.Employee;
import com.ccit.domain.PageBean;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface EmployeeDao {

    @Insert("insert into employee (id,employeeName,department,position) values(#{id},#{employeeName},#{department},#{position})")
    public int add(Employee employee);

    //通过Id查询员工信息
    @Select("select * from employee where id = #{id}")
    public Employee getById(Integer id);

    //查询所有员工信息
    @Select("select * from employee")
    public List<Employee> selectAll();

    //修改
    @Update("update employee set id = #{id} , employeeName = #{employeeName}, department = #{department} , position= #{position} where id = #{id}")
    public int update(Employee employee);

    //将 "approval" 表中的员工ID和员工姓名更新为与 "employee" 表中相匹配的对应值
    @Update("UPDATE approval \n" +
            "JOIN employee  ON approval.employeeId = employee.id \n" +
            "SET approval.employeeId = employee.id, \n" +
            "    approval.employeeName = employee.employeeName;\n" +
            "\t")
    public int updateApproval(Employee employee);

    //将 "attendance" 表中的员工ID和员工姓名更新为与 "employee" 表中相匹配的对应值
    @Update("UPDATE attendance \n" +
            "JOIN employee  ON attendance.employeeId = employee.id \n" +
            "SET attendance.employeeId = employee.id, \n" +
            "    attendance.employeeName = employee.employeeName;\n" +
            "\t")
    public int updateAttendance(Employee employee);
    //将 "punch" 表中的员工ID和员工姓名更新为与 "employee" 表中相匹配的对应值
    @Update("UPDATE punch \n" +
            "JOIN employee  ON punch.employeeId = employee.id \n" +
            "SET punch.employeeId = employee.id, \n" +
            "    punch.employeeName = employee.employeeName;\n" +
            "\t")
    public int updatePunch(Employee employee);

    //根据ID删除
    @Delete("delete from employee where id = #{id}")
    public int delete(Integer id);

    @Delete("DELETE FROM attendance WHERE employeeId = #{id};")
    public int deleteAttendance(Integer id);


    /**
     * 分页查询
     * @param begin
     * @param size
     * @return
     */
    @Select("select * from employee limit #{begin} , #{size}")
    List<Employee> selectByPage(@Param("begin") int begin,@Param("size") int size);


    /**
     * 查询总记录数
     * @return
     */
    @Select("select count(*) from employee ")
    int selectTotalCount();


    /**
     * 批量删除
     * @param ids
     */
    @Delete({
            "<script>",
            "DELETE FROM employee WHERE id IN",
            "<foreach collection='ids' item='id' separator=',' open='(' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"
    })
    public int deleteByIds(@Param("ids") Integer[] ids);


}
